package com.freight.order.controller;

import com.freight.core.common.annotation.SystemLog;
import com.freight.core.common.enums.LogType;
import com.freight.core.common.utils.PageUtil;
import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.PageVo;
import com.freight.core.common.vo.Result;
import com.freight.core.common.vo.SearchVo;
import com.freight.order.dto.OrderGoodsDto;
import com.freight.order.entity.OrderGoods;
import com.freight.order.service.OrderGoodsService;
import com.freight.order.vo.ForwardDriverVo;
import com.freight.order.vo.GoodPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author huyingtai
 */
@Slf4j
@RestController
@Api(description = "")
@RequestMapping("/freight/orderGoods")
@Transactional
public class OrderGoodsController  {

    @Autowired
    private OrderGoodsService orderGoodsService;


    @RequestMapping(value = "/getGoodPage", method = RequestMethod.GET)
    @ApiOperation(value = "平台首页 --- 获取货物信息 ----")
    public Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<GoodPageVo>> getGoodPage( PageVo pageVo) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<GoodPageVo> page = orderGoodsService.getGoodPage(PageUtil.initMpPage(pageVo));
        return new ResultUtil<com.baomidou.mybatisplus.extension.plugins.pagination.Page<GoodPageVo>>().setData(page);
    }

    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "多条件分页获取货源列表")
    public Result<Page<OrderGoods>> getByCondition(OrderGoods orderGoods, SearchVo searchVo, PageVo pageVo) {
        Page<OrderGoods> page = orderGoodsService.findByCondition(orderGoods, searchVo, PageUtil.initPage(pageVo));
        return new ResultUtil<Page<OrderGoods>>().setData(page);
    }

    @RequestMapping(value = "/getdriverPage", method = RequestMethod.GET)
    @ApiOperation(value = "平台端 --- 获取司机列表 -----")
    public Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo>> getdriverPage(Long goodsId,String vehicleNum, String name, PageVo pageVo, String vehicleState) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo> page = orderGoodsService.getdriverPage(goodsId,vehicleNum, name, PageUtil.initMpPage(pageVo),vehicleState);
        return new ResultUtil<com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo>>().setData(page);
    }

    @RequestMapping(value = "/getCompanyDriverPage", method = RequestMethod.GET)
    @ApiOperation(value = "货主端 --- 获取司机列表 -----")
    public Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo>> getCompanyDriverPage(Long goodsId,String vehicleNum, String name, PageVo pageVo, String vehicleState) {
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo> page = orderGoodsService.getCompanyDriverPage(goodsId,vehicleNum, name, PageUtil.initMpPage(pageVo),vehicleState);
        return new ResultUtil<com.baomidou.mybatisplus.extension.plugins.pagination.Page<ForwardDriverVo>>().setData(page);
    }

    @RequestMapping(value = "/getActualdriverPage", method = RequestMethod.POST)
    @ApiOperation(value = "平台端 --- 添加车辆 ----- 获取司机列表")
    public Result<List<ForwardDriverVo>> getActualdriverPage(String searchContent) {
        List<ForwardDriverVo> list = orderGoodsService.getActualdriverPage(searchContent);
        return new ResultUtil<List<ForwardDriverVo>>().setData(list);
    }

    @RequestMapping(value = "/getCompanyActualdriverPage", method = RequestMethod.POST)
    @ApiOperation(value = "货主端 --- 添加车辆 ----- 获取司机列表")
    public Result<List<ForwardDriverVo>> getCompanyActualdriverPage(String searchContent) {
        List<ForwardDriverVo> list = orderGoodsService.getCompanyActualdriverPage(searchContent);
        return new ResultUtil<List<ForwardDriverVo>>().setData(list);
    }

    @RequestMapping(value = "/getNotLoadingTime", method = RequestMethod.POST)
    @ApiOperation(value = "根据货源id获取未抢单的装货时间 -----")
    public Result<List<String>> getNotLoadingTime(Long goodId) {
        List<String> list = orderGoodsService.getLoadingTime(goodId,"1");
        return new ResultUtil<List<String>>().setData(list);
    }

    @RequestMapping(value = "/getLoadingTime", method = RequestMethod.POST)
    @ApiOperation(value = "根据货源id获取全部装货时间 -----")
    public Result<List<String>> getLoadingTime(Long goodId) {
        List<String> list = orderGoodsService.getLoadingTime(goodId,null);
        return new ResultUtil<List<String>>().setData(list);
    }

    @RequestMapping(value = "/publicGoods", method = RequestMethod.POST)
    @ApiOperation(value = "发布货源需求 -----")
    @SystemLog(description = "平台发布货源", type = LogType.OPERATION)
    public Result<OrderGoods> publicGoods(OrderGoodsDto orderGoodsDto) {
        String res = orderGoodsService.publicGoods(orderGoodsDto);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/updateGoods", method = RequestMethod.POST)
    @ApiOperation(value = "修改货源信息 ----")
    @SystemLog(description = "平台修改货源信息", type = LogType.OPERATION)
    public Result<OrderGoods> updateGoods(OrderGoodsDto orderGoodsDto,Long goodId) {
        String res = orderGoodsService.updateGoods(orderGoodsDto,goodId);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/delGoods", method = RequestMethod.POST)
    @ApiOperation(value = "删除货源信息")
    @SystemLog(description = "平台删除货源信息", type = LogType.OPERATION)
    public Result<OrderGoods> delGoods(Long goodId) {
        String res = orderGoodsService.delGoods(goodId);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/updateGoodsStatus", method = RequestMethod.POST)
    @ApiOperation(value = "修改货源状态 --- 关闭、开启、完结")
    public Result<OrderGoods> updateGoodsStatus(Long goodId,Integer status) {
        String res = orderGoodsService.updateGoodsStatus(goodId,status);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/toExamineGoods", method = RequestMethod.POST)
    @ApiOperation(value = "平台审核货源 ----")
    @SystemLog(description = "平台审核货源信息", type = LogType.OPERATION)
    public Result<String> toExamineGoods(Long goodId, Integer status, String reason) {
        orderGoodsService.toExamineGoods(goodId,status,reason);
        return ResultUtil.success("操作成功");
    }

    @RequestMapping(value = "/delGoodsLists", method = RequestMethod.POST)
    @ApiOperation(value = "批量删除货源信息 ----")
    public Result<OrderGoods> delGoods(Long[] goodIds) {
        String res = orderGoodsService.delGoodsList(goodIds);
        return ResultUtil.success(res);
    }

    @RequestMapping(value = "/getHistoryGood", method = RequestMethod.POST)
    @ApiOperation(value = "历史货源")
    public Result<List<OrderGoods>> getHistoryGood(Long userId) {
        List<OrderGoods> res =  orderGoodsService.getHistoryGood(userId);
        return  new ResultUtil<List<OrderGoods>>().setData(res);
    }


}
